package com.qf.controller;

import com.qf.common.dto.NewsDto;
import com.qf.common.vo.R;
import com.qf.entity.News;
import com.qf.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description: cool新闻
 * @author: No1
 * @create: 2020-11-30 11:33:07
 */
@RestController
@RequestMapping("/api/news")
public class NewsController {
    @Autowired
    private NewsService newsService;
//    //新增
//    @PostMapping("/add.do")
//    public R save(@RequestBody News news){
//        return newsService.save(news);
//    }
//    //删除
//    @DeleteMapping("/del.do")
//    public R del(int id){
//        return newsService.delById(id);
//    }
    //查询
    @GetMapping("/all.do")
    public R all(@RequestParam String tid){
        R all = newsService.all(tid);
        List<NewsDto> data = (List<NewsDto>) all.getData();
        for (NewsDto datum : data) {
            System.out.println(datum);
        }
        return all;
    }

    @GetMapping("/insertNpraise.do")
    public R insertNpraise(@RequestParam String id, @RequestParam String aid) {
        return newsService.insertNpraise(id, aid);
    }

    @GetMapping("/insertComment.do")
    public R insertComment(@RequestParam String id, @RequestParam String aid, @RequestParam String comment) {
        return newsService.insertComment(id, aid, comment);
    }

    @GetMapping("/delById.do")
    public R delById(@RequestParam int id) {
        return newsService.delById(id);
    }

    @GetMapping("/insert.do")
    public R insert(@RequestParam News news) {
        return R.ok(newsService.insert(news));
    }
}